package com.team.recruitment_management_system.controller;

import com.team.recruitment_management_system.pojo.dto.role.AddRoleDto;
import com.team.recruitment_management_system.pojo.dto.role.ChangeRoleInfoDto;
import com.team.recruitment_management_system.pojo.dto.role.RolePageQuery;
import com.team.recruitment_management_system.pojo.vo.OptionVo;
import com.team.recruitment_management_system.pojo.vo.RoleInfoVo;
import com.team.recruitment_management_system.security.OperationLogAnnotation;
import com.team.recruitment_management_system.service.SysRoleService;
import com.team.recruitment_management_system.util.result.PageResult;
import com.team.recruitment_management_system.util.result.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/role")
@Tag(name = "4.角色模块")
public class RoleController {
    @Autowired
    private SysRoleService sysRoleService;

    @GetMapping("/one/{id}")
    @Operation(summary = "根据id获取角色", security = {@SecurityRequirement(name = "Authorization")})
    @OperationLogAnnotation(operModul = "角色模块", operType = "查询", operDesc = "根据id获取角色")
    public Result<RoleInfoVo> getRoleById(@PathVariable int id) {
        return sysRoleService.getRoleById(id);
    }

    @GetMapping("/more")
    @Operation(summary = "获取角色分页", security = {@SecurityRequirement(name = "Authorization")})
    @OperationLogAnnotation(operModul = "角色模块", operType = "查询", operDesc = "获取角色分页")
    public PageResult<RoleInfoVo> getRoleById(RolePageQuery pageQuery) {
        return sysRoleService.getRolePage(pageQuery);
    }

    @PostMapping("/one")
    @Operation(summary = "添加角色", security = {@SecurityRequirement(name = "Authorization")})
    @OperationLogAnnotation(operModul = "角色模块", operType = "插入", operDesc = "添加角色")
    public Result<Void> addRole(@RequestBody AddRoleDto addRoleDto) {
        return sysRoleService.addRole(addRoleDto);
    }

    @PutMapping("/one")
    @Operation(summary = "修改角色", security = {@SecurityRequirement(name = "Authorization")})
    @OperationLogAnnotation(operModul = "角色模块", operType = "修改", operDesc = "修改角色")
    public Result<Void> updateRole(@RequestBody ChangeRoleInfoDto changeRoleInfoDto) {
        return sysRoleService.updateRole(changeRoleInfoDto);
    }

    @PutMapping("/one/status/{id}")
    @Operation(summary = "取消停用角色", security = {@SecurityRequirement(name = "Authorization")})
    @OperationLogAnnotation(operModul = "角色模块", operType = "修改", operDesc = "取消停用角色")
    public Result<Void> unDisableRoleStatus(@PathVariable Long id) {
        return sysRoleService.changeRoleStatus(id, false);
    }

    @DeleteMapping("/one/status/{id}")
    @Operation(summary = "停用角色", security = {@SecurityRequirement(name = "Authorization")})
    @OperationLogAnnotation(operModul = "角色模块", operType = "删除", operDesc = "停用角色")
    public Result<Void> disableRoleStatus(@PathVariable Long id) {
        return sysRoleService.changeRoleStatus(id, true);
    }


    @DeleteMapping("/one/{id}")
    @Operation(summary = "删除角色", security = {@SecurityRequirement(name = "Authorization")})
    @OperationLogAnnotation(operModul = "角色模块", operType = "删除", operDesc = "删除角色")
    public Result<Void> deleteRole(@PathVariable Long id) {
        return sysRoleService.deleteRole(id);
    }

    @GetMapping("/option")
    @Operation(summary = "获取角色选项", security = {@SecurityRequirement(name = "Authorization")})
    @OperationLogAnnotation(operModul = "角色模块", operType = "查询", operDesc = "获取角色选项")
    public Result<List<OptionVo>> deleteRole() {
        return sysRoleService.getRoleOptions();
    }
}
